import { MikroORM } from "@mikro-orm/core";
import { logger } from "@mikro-orm/nestjs";
import { SqlHighlighter } from "@mikro-orm/sql-highlighter";

(async () => {
    const orm = await MikroORM.init({
      discovery: {
        // we need to disable validation for no entities
        warnWhenNoEntities: false,
      },
      contextName:'zp',
      dbName: 'zp_apesk_net',
      user:'zp_apesk_net',
      password:'88888888',
      type: 'mysql',
      port: 3306,
      allowGlobalContext:true,
      highlighter: new SqlHighlighter(),
      entities: ['./src/modules/job/databases/schemas'],
      //debug: true,
      //logger: logger.log.bind(logger),
    });
    const generator = orm.getSchemaGenerator();

    // const dropDump = await generator.getDropSchemaSQL();
    // console.log(dropDump);
  
    // const createDump = await generator.getCreateSchemaSQL();
    // console.log(createDump);
  
    // const updateDump = await generator.getUpdateSchemaSQL();
    // console.log(updateDump);
  
    // // there is also `generate()` method that returns drop + create queries
    const dropAndCreateDump = await generator.generate();
    console.log(dropAndCreateDump);
  
    // or you can run those queries directly, but be sure to check them first!
    // await generator.dropSchema();
    // await generator.createSchema();
    //await generator.updateSchema();
  
    // in tests it can be handy to use those:
    // await generator.refreshDatabase(); // ensure db exists and is fresh
    // await generator.clearDatabase(); // removes all data
  
    await orm.close(true);
  })();